<?php
	
	/**
	* Featured Product List Module
	*
	* @version $Id: mod_mallkit_featured.php 0001 2009-01-15 10:29:00 saurabh_atr $
	* @package Mallkit
	* @subpackage Modules
	*
	* @copyright Copyright (C) 2004-2009 saurabh - All rights reserved.
	* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
	* Mallkit eCommerce is free software. This version may have been modified pursuant
	* to the GNU General Public License, and as distributed it includes or
	* is derivative of works licensed under the GNU General Public License or
	* other free or open source software licenses.
	* See /administrator/components/com_mallkit/COPYRIGHT.php for copyright notices and details.
	*
	* http://www.mallkit.org
	*/
	
	// no direct access
	defined('_JEXEC') or die('Restricted access');
	jimport('phpxmlrpc.xmlrpc');

	function display_children($parent_id = 0, $level = 1, $ul = 1, $count= 1, $categories_level_count, $limit)
	{
		// get joomla instance of client
		$host = JURI::getInstance();
		
		// get host of clients joomla instance and set it to the $host variable
		$host = $host->getHost();
		
		// get the clients true joomla instance root (path-only)
		$instance_path = JURI::root(true);
		// append the xmlrpc directory and set to the $path variable
		$xml_path = JURI::root(true)."/xmlrpc/";
			
		// create an instance of client implementation
		$client = new xmlrpc_client($xml_path, $host);
		
		// define global xmlrpc variable types
		global $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;

		// pass the value to xmlrpc
		$msg = new xmlrpcmsg("mallkit.getCategoriesList", array(new xmlrpcval(0, $xmlrpcString), new xmlrpcval($parent_id, $xmlrpcInt), new xmlrpcval($limit, $xmlrpcInt)));

		// fetching value back from xmlrpc
		$response = $client->send($msg);

		// BEGIN - FEATURED PRODUCT LIST
		if ((boolean)$response->value()) 
		{

			// decoding the xmlrpc response into array
			$products = php_xmlrpc_decode($response->value());

			// extracting the array returned from xmlrpc and display in module
			foreach($products as $product) 
			{
				$count++;
				if($ul == ($level - 1))
				{
					echo '<ul>';
					$ul++;
				}
			// display category
			echo '<li><a href="#">' . $product['category'] . '</a></li>';
			if($level < $categories_level_count) display_children($product['category_id'], $level+1, $ul, $count, $categories_level_count, $limit);
			if($ul == ($level))
			{
				echo '</ul>';
				$ul--;
			}
		}
	}
	else
	{
		echo "Error to procedure call.";
	}
}
echo '<ul>';
display_children(0, 1, 1, 1, $params->get('categories_level_count'), $params->get('categories_limit'));
echo '</ul>';
?>